import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-03-31
 * Time: 17:24
 */

/**
 *      反射私有的构造方法屏蔽内容为获得公有的构造方法
 */
public class Demo2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class c2=null;
        c2=Class.forName("Student");
        Constructor declaredConstructorStudent=
                c2.getDeclaredConstructor(String.class,int.class);
        declaredConstructorStudent.setAccessible(true);
        Object object=declaredConstructorStudent.newInstance("牛奶",20);
        Student student=(Student) object;
        System.out.println(student);

    }
}
